package com.xbfinal.eduservice.controller;



import com.xbfinal.commonUtils.Result;
import com.xbfinal.eduservice.entity.EduChapter;
import com.xbfinal.eduservice.entity.chapter.ChapterVo;
import com.xbfinal.eduservice.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author xbfinal
 * @since 2023-01-09
 */
@Api(value = "课程章节管理")
@RestController
@Slf4j
@RequestMapping("/eduservice/chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;

    /**
     * 课程大纲列表
     * @return
     */
    @ApiOperation("课程大纲列表")
    @GetMapping("getChapterVideo/{courseId}")
    public Result getChapterVideo(@PathVariable("courseId")String courseId){
        log.info("课程大纲列表",courseId);
        List<ChapterVo> list
                =chapterService.getChapterVideoByCourseId(courseId);

        return Result.ok().add("allChapterVideo",list);
    }

    /**
     * 添加章节
     * @param eduChapter
     * @return
     */
    @ApiOperation("添加章节")
    @PostMapping("/addChapter")
    public Result addChapter(@RequestBody EduChapter eduChapter){
        log.info("添加章节",eduChapter.toString());
        chapterService.save(eduChapter);
        return Result.ok();
    }
    /**
     * 修改章节
     * @param eduChapter
     * @return
     */
    @ApiOperation("修改章节")
    @PostMapping("/updateChapter")
    public Result updateChapter(@RequestBody EduChapter eduChapter){

        log.info("修改章节",eduChapter);
        chapterService.updateById(eduChapter);
        return  Result.ok();
    }

    /**
     * 根据id查询
     * @param chapterId
     * @return
     */
    @ApiOperation("根据id查询")
    @GetMapping("getChapterInfo/{chapterId}")

    public Result getChapterInfo(@PathVariable("chapterId") String chapterId){
        log.info("根据id查询",chapterId);
        EduChapter byId = chapterService.getById(chapterId);
        return Result.ok().addData(byId);
    }



    @ApiOperation("删除章节")
    @DeleteMapping("deleteChapter/{chapterId}")
    public Result deleteChapter(@PathVariable("chapterId") String chapterId){
        log.info("chapterId",chapterId);
        chapterService.deleteChapter(chapterId);
        return Result.ok();
    }

}

